<div class="mat-elevation-z1">
  <mat-toolbar>
    <span class="toolbar-title">上次交易</span>
    <span class="spacer"></span>
    <!--<button mat-stroked-button color="primary" (click)="editNew()">
      <mat-icon>add_circle_outline</mat-icon>
      新建
    </button>-->
  </mat-toolbar>

  <table mat-table class="full-width" matSort matSortActive="updateTs" matSortDirection="desc">

    <ng-container matColumnDef="index">
      <th mat-header-cell *matHeaderCellDef>#</th>
      <td mat-cell *matCellDef="let row; let index=index">
        {{index + 1}}
      </td>
    </ng-container>

    <ng-container matColumnDef="concerned">
      <th mat-header-cell *matHeaderCellDef mat-sort-header start="desc">
        <mat-icon>star_outline</mat-icon>
      </th>
      <td mat-cell *matCellDef="let row">
        <mat-icon class="clickable" [class.favorite]="row.pair?.concerned" (click)="toggleConcern(row.pair)">
          {{row.pair?.concerned ? 'star' : 'star_outline'}}
        </mat-icon>
      </td>
    </ng-container>

    <ng-container matColumnDef="baseCcy">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>基础币种</th>
      <td class="ccy-logo-code" mat-cell *matCellDef="let row">
        <img class="ccy-logo" [src]="CoinLogoPath(row.baseCcy)" alt="">
        <div class="ccy-code">{{row.baseCcy}}</div>
      </td>
    </ng-container>

    <ng-container matColumnDef="quoteCcy">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>报价币种</th>
      <td class="ccy-logo-code" mat-cell *matCellDef="let row">
        <img class="ccy-logo" [src]="CoinLogoPath(row.quoteCcy)" alt="">
        <div class="ccy-code">{{row.quoteCcy}}</div>
      </td>
    </ng-container>

    <ng-container matColumnDef="side">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>方向</th>
      <td mat-cell *matCellDef="let row"
          [class.order-side-buy]="row.side==='buy'"
          [class.order-side-sell]="row.side==='sell'">
        {{row.side}}
      </td>
    </ng-container>

    <ng-container matColumnDef="avgPrice">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>均价</th>
      <td mat-cell *matCellDef="let row">
        {{row.avgPrice | money}}
      </td>
    </ng-container>

    <ng-container matColumnDef="execQty">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>基础币种数量</th>
      <td mat-cell *matCellDef="let row">
        {{row.execQty | money}}
      </td>
    </ng-container>

    <ng-container matColumnDef="quoteAmount">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>报价币种数量</th>
      <td mat-cell *matCellDef="let row">
        {{row.quoteAmount | money}}
      </td>
    </ng-container>

    <ng-container matColumnDef="ex">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>交易所</th>
      <td mat-cell *matCellDef="let row">{{row.ex}}</td>
    </ng-container>

    <ng-container matColumnDef="updateTs">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>交易时间</th>
      <td mat-cell *matCellDef="let row">{{row.updateTs | date:'MM-dd HH:mm'}}</td>
    </ng-container>

    <ng-container matColumnDef="actions">
      <th mat-header-cell *matHeaderCellDef></th>
      <td mat-cell *matCellDef="let row" align="end">

        <button mat-button [matMenuTriggerFor]="actions">
          <mat-icon>more_vert</mat-icon>
        </button>
        <mat-menu #actions="matMenu">
          <button mat-menu-item (click)="showOrderDetail(row)" *ngIf="row.oid">
            <mat-icon>details</mat-icon>
            详情
          </button>
          <!--<button mat-menu-item (click)="edit(row)">
            <mat-icon>edit</mat-icon>
            修改
          </button>-->
          <button mat-menu-item (click)="remove(row)">
            <mat-icon>remove_circle_outline</mat-icon>
            删除
          </button>
        </mat-menu>

      </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
  </table>

  <mat-paginator #paginator
                 [length]="dataSource?.data?.length"
                 [pageIndex]="0"
                 [pageSize]="20"
                 [pageSizeOptions]="[10, 20, 50, 100]">
  </mat-paginator>

</div>
